package com.sfx.concurrent.demo.concurrent.ReentrantLock;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.ReentrantLock;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-01-09
 * Time: 16:01
 */
@Slf4j
public class TestDemo {
    //创建一个ReentrantLock对象
    private static ReentrantLock lock =new ReentrantLock();
    public static void main(String[] args) {
        //调用lock方法加锁
        lock.lock();
        try{
            //临界区的代码
        }finally {
            //必须对其进行解锁,所以放在finally块
            lock.unlock();
        }
    }
}
